package com.shujia.sql

import org.apache.flink.table.api.{EnvironmentSettings, TableEnvironment}

object Demo5BlackHole {
  def main(args: Array[String]): Unit = {
    val setting: EnvironmentSettings = EnvironmentSettings
      .newInstance()
      .inStreamingMode()
      .build()

    val table: TableEnvironment = TableEnvironment.create(setting)

    /**
      * 创建一个source表
      *
      */

    table.executeSql(
      """
        |CREATE TABLE words (
        |  word STRING
        |) WITH (
        |  'connector' = 'kafka',
        |  'topic' = 'words',
        |  'properties.bootstrap.servers' = 'master:9092',
        |  'properties.group.id' = 'testGroup',
        |  'scan.startup.mode' = 'earliest-offset',
        |  'format' = 'csv',
        |  'csv.field-delimiter'='\t',
        |  'csv.ignore-parse-errors' = 'true'
        |)
      """.stripMargin)

    /**
      * blackhole: 一般用于高性能测试
      *
      */

    table.executeSql(
      """
        |CREATE TABLE blackhole_table
        |WITH ('connector' = 'blackhole')
        |LIKE words (EXCLUDING ALL)
        |
      """.stripMargin)

    table.executeSql(
      """insert into blackhole_table
        |select * from words
        |
      """.stripMargin)

  }

}
